﻿using System;
using SuckerPunch.IsolatedModel;
using SuckerPunch.SettingsUI;

namespace SuckerPunch.Presenters
{
    class ConnectionPresenter
    {
        private SettingsUI.Connection _view;
        private SettingsModel _model;

        public ConnectionPresenter(SettingsUI.Connection connectionView)
        {
            _view = connectionView;
            _model = new SettingsModel();
            WireView();
        }

        private void WireView()
        {
            _view.Load += new EventHandler(_view_Load);
            _view.InvisibleCheckBox.CheckedChanged += new EventHandler(InvisibleCheckBox_CheckedChanged);
            _view.ConnectButton.Click += new EventHandler(ConnectButton_Click);
            
        }

        void _view_Load(object sender, EventArgs e)
        {
            Connection current = _model.GetConnectionSettings();
            PopulateViewForm(current);
        }

        private void PopulateViewForm(Connection current)
        {
            _view.FullNameTextBox.Text = current.FullName;
            _view.EmailAddressTextBox.Text = current.Email;
            _view.NickNameTextBox.Text = current.NickName;
            _view.AlternativeTextBox.Text = current.Alternative;
            _view.InvisibleCheckBox.Checked = current.IsInvisible;

        }

        void ConnectButton_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        void InvisibleCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
        
        private void SaveSettings()
        {
            Connection connection = new Connection();
            connection.FullName = _view.FullNameTextBox.Text;
            connection.Email = _view.EmailAddressTextBox.Text;
            connection.NickName = _view.NickNameTextBox.Text;
            connection.Alternative = _view.AlternativeTextBox.Text;
            connection.IsInvisible = _view.InvisibleCheckBox.Checked;

            _model.SaveConnectionSettings(connection);
        }
    }
}
